﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CustomsSystem.BLL;
using CustomsSystem.Model;
using Maticsoft.Common;
namespace WEB.user
{
    public partial class authManage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind();
                
            }
            if ((bool )Session["权限管理"] != true)
            {
               Response .Write ("<Script language=JavaScript>alert('对不起,您没有权限查看该页面！');;history.back();</Script>");
 
            }
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void search_Click(object sender, EventArgs e)
        {
            
            bind();
        }
        /// <summary>
        /// 显示全部权限列表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void showAllUsers_Click(object sender, EventArgs e)
        {
            txtKey.Text = "";
            DataSet users = new CustomsSystem.BLL.AuthManage ().GetAllList();
            gvauthview.DataSource = users;
            gvauthview.DataBind();
        }
        protected void bind()
        {
            if (Request.QueryString["empnum"] != null)
            {
                txtKey.Text = Request.QueryString["empnum"].ToString() ; 
             }
            string strWhere = " UserName like '%" + txtKey.Text.Trim() + "%' or EMPNUM LIKE '%" + txtKey.Text.Trim() + "%' ";
                DataSet users = new CustomsSystem.BLL.AuthManage().GetList(strWhere);
                gvauthview.DataSource = users;
                gvauthview.DataBind();
           
        }
        /// <summary>
        /// 编辑事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvauthview_RowEditing(object sender, GridViewEditEventArgs e)
        {
            
            gvauthview.EditIndex = e.NewEditIndex;
            bind();
        
        }
        /// <summary>
        /// 取消编辑状态
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvauthview_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            gvauthview.EditIndex = -1;
            bind();
           
        }
        /// <summary>
        /// 更新本行数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvauthview_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {

            #region 获取值
            CheckBox cb1 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbplanEdit");
            CheckBox cb2 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbplanNView");
            CheckBox cb3 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbplanFView");
            CheckBox cb4 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbplanView");


            CheckBox cb5 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbWorkFlowView");
            CheckBox cb6 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbSheetEdit");
            CheckBox cb7 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbSheetView0");
            CheckBox cb8= (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbUpdocument");
            CheckBox cb9 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbIndex_document");


            CheckBox cb10 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbCustomerView");
            CheckBox cb11 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbcustomerEdit");
            CheckBox cb42 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("CheckBox1");


            CheckBox cb12 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbBillView");
            CheckBox cb13 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbMonthCustomView");
            CheckBox cb14 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbAudit");
            CheckBox cb15 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbReject");
            CheckBox cb16 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbReceivables");
            CheckBox cb17 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbActualReceivables");


            CheckBox cb18 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbExcel_docment");
            CheckBox cb19 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbYSshou");
            CheckBox cb20 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbyuangongyewutongji");
            CheckBox cb21 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbyewushujutongji");


            CheckBox cb22 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbScoreView");
            CheckBox cb23 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbMessage");


            CheckBox cb24 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbKnowledgeView0");
            CheckBox cb25 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbKnowledgeView1");
            CheckBox cb26 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbKnowledgeView2");
            CheckBox cb27 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbKnowledgeView3");
            CheckBox cb28 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbknowledgeView5");
            CheckBox cb29 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbKnowledgeUpload");


            CheckBox cb30 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbindex_fee");
            CheckBox cb31 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbfeeTemplateView");
            CheckBox cb32 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbmodelset");
            CheckBox cb33 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbEXCELSetting");
            CheckBox cb34 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbAddCode");
            CheckBox cb35 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbIndex_job");
            CheckBox cb36 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbCodeIndex");
            CheckBox cb37 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbEmpIndex");
            CheckBox cb38 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbAddEmp");
            CheckBox cb39 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbUserPasswordChange");


            CheckBox cb40 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbAuthManage");
            CheckBox cb41 = (CheckBox)gvauthview.Rows[e.RowIndex].FindControl("cbDatabase");


            #endregion

            #region 处理值
            string EMPNUM = gvauthview.Rows[e.RowIndex].Cells[0].Text;
            string UserName = gvauthview.Rows[e.RowIndex].Cells[1].Text;
            //业务预期
            bool 工作计划 = false;
            bool 工作计划录入 = cb1.Checked;
            bool 当天业务查看 = cb2.Checked;
            bool 将来业务查看 = cb3.Checked;
            bool 查看业务计划 = cb4.Checked;
            if (工作计划录入 == true || 当天业务查看 == true || 将来业务查看 == true || 查看业务计划 == true)
            { 工作计划 = true; }
            //业务管理
            bool 业务管理 = false;
            bool 查看任务列表 = cb5.Checked;
            bool 委托单录入 = cb6.Checked;
            bool 委托单查看 = cb7.Checked;
            bool 报关单证上载 = cb8.Checked;
            bool 上载单证查看 = cb9.Checked;
            if (委托单录入 == true || 查看任务列表 == true || 报关单证上载 == true || 委托单查看 == true || 上载单证查看 == true)
            { 业务管理 = true; }

            //客户管理
            bool 客户管理 = false;
            bool 查看客户信息 = cb10.Checked;
            bool 增加客户信息 = cb11.Checked;
            bool 合同管理 = cb42.Checked;
            if (查看客户信息 == true || 增加客户信息 == true || 合同管理==true )
            { 客户管理 = true; }

            //费用结算
            bool 费用结算 = false;
            bool 结算单 = cb13.Checked;
            bool 对账单 = cb12.Checked;
            bool 审核费用 = cb14.Checked;
            bool 反审核 = cb15.Checked;
            bool 费用录入 = cb16.Checked;
            bool 费用销账 = cb17.Checked;
            if (结算单 == true || 对账单 == true || 审核费用 == true || 反审核 == true || 费用录入 == true|| 费用销账 == true)
            { 费用结算 = true; }

            //统计分析
            bool 统计分析 = false;
            bool 单证交接签收表 = cb18.Checked;

            bool 应实收统计 = cb19.Checked;
            bool 员工业务统计 = cb20.Checked;
            bool 业务数据统计 = cb21.Checked;
            if (应实收统计 == true || 单证交接签收表 == true || 员工业务统计 == true || 业务数据统计 == true)
            { 统计分析 = true; }
            //客户互动
            bool 客户互动 = false;
            bool 客户意见反馈栏 = cb22.Checked;

            bool 短信发送 = cb23.Checked;
            if (客户意见反馈栏 == true || 短信发送 == true)
            { 客户互动 = true; }
            //知识分享
            bool 知识分享 = false;
            bool 行业法律法规 = cb24.Checked;
            bool 业务流程 = cb25.Checked;
            bool 典型案例 = cb26.Checked;
            bool 管理公告 = cb27.Checked;
            bool 港口情况 = cb28.Checked;
            bool 资源上传 = cb29.Checked;
            if (港口情况 == true || 行业法律法规 == true || 业务流程 == true || 典型案例 == true || 管理公告 == true || 资源上传 == true)
            { 知识分享 = true; }
            //基础资料设置
            bool 基础资料设置 = false;
            bool 费用类别设置 = cb30.Checked;
            bool 费用模板设置 = cb31.Checked;
            bool 单证模板设置 = cb32.Checked;
            bool EXCEL模板设置 = cb33.Checked;
            bool 基础代码设置 = cb34.Checked;
            bool 岗位设置 = cb35.Checked;
            bool 代码查询 = cb36.Checked;
            bool 查看人员 = cb37.Checked;
            bool 增加人员 = cb38.Checked;
            bool 密码修改 = cb39.Checked;




            if (单证模板设置 == true || 费用模板设置 == true || 费用类别设置 == true || EXCEL模板设置 == true || 基础代码设置 == true || 代码查询 == true || 查看人员 == true || 增加人员 == true || 密码修改 == true || 岗位设置 == true)
            { 基础资料设置 = true; }
            //系统管理
            bool 系统管理 = false;
            bool 权限管理 = cb40.Checked;
            bool 数据管理 = cb41.Checked;
            if (数据管理 == true || 权限管理 == true)
            { 系统管理 = true; }
            #endregion
            #region 传入MODEL
            CustomsSystem.Model.Auth model = new CustomsSystem.Model.Auth();
            model.EmpNum = EMPNUM;
            model.UserName = UserName;

            model.工作计划 = 工作计划;
            model.工作计划录入 = 工作计划录入;
            model.当天业务查看 = 当天业务查看;
            model.将来业务查看 = 将来业务查看;
            model.查看业务计划 = 查看业务计划;

            model.业务管理 = 业务管理;
            model.查看任务列表 = 查看任务列表;
            model.委托单录入 = 委托单录入;
            model.委托单查看 = 委托单查看;
            model.报关单证上载 = 报关单证上载;
            model.上载单证查看 = 上载单证查看;

            model.客户管理 = 客户管理;
            model.查看客户信息 = 查看客户信息;
            model.增加客户信息 = 增加客户信息;
            model.合同管理 = 合同管理;

            model.费用结算 = 费用结算;
            model.费用录入 = 费用录入;
            model.审核费用 = 审核费用;
            model.反审核 = 反审核;
            model.费用销账 = 费用销账;
            model.对账单 = 对账单;
            model.结算单 = 结算单;


            model.统计分析 = 统计分析;
            model.应实收统计 = 应实收统计;
            model.单证交接签收表 = 单证交接签收表;
            model.员工业务统计 = 员工业务统计;
            model.业务数据统计 = 业务数据统计;

            model.客户互动 = 客户互动;
            model.客户意见反馈栏 = 客户意见反馈栏;
            model.短信发送 = 短信发送;

            model.知识分享 = 知识分享;
            model.行业法律法规 = 行业法律法规;
            model.业务流程 = 业务流程;
            model.典型案例 = 典型案例;
            model.管理公告 = 管理公告;
            model.港口情况 = 港口情况;
            model.资源上传 = 资源上传;


            model.基础资料设置 = 基础资料设置;
            model.费用类别设置 = 费用类别设置;
            model.费用模板设置 = 费用模板设置;
            model.单证模板设置 = 单证模板设置;
            model.EXCEL模板设置 = EXCEL模板设置;
            model.基础代码设置 = 基础代码设置;
            model.代码查询 = 代码查询;
            model.岗位设置 = 岗位设置;
            model.查看人员 = 查看人员;
            model.增加人员 = 增加人员;
            model.密码修改 = 密码修改;


            model.系统管理 = 系统管理;
            model.权限管理 = 权限管理;
            model.数据管理 = 数据管理;

            CustomsSystem.BLL.AuthManage bll = new AuthManage();
            bll.Update(model);
            gvauthview.EditIndex = -1;
            bind();
           
            Maticsoft.Common.MessageBox.Show(this, "保存成功！"); 
            #endregion
        }

        protected void gvauthview_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvauthview.PageIndex = e.NewPageIndex;
            bind();
           
        }
        #region 全选事件
        /// <summary>
        /// 全选
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void cbALL_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < gvauthview.Rows.Count; i++)
            {
               
                CheckBox cb1 = (CheckBox)gvauthview.Rows[i].FindControl("cbplanEdit");
                CheckBox cb2 = (CheckBox)gvauthview.Rows[i].FindControl("cbplanNView");
                cb2.Checked = this.cbALL1.Checked;
                cb1.Checked = this.cbALL1.Checked;
            }
        }

     

        protected void cbALL2_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < gvauthview.Rows.Count; i++)
            {
                CheckBox cb3 = (CheckBox)gvauthview.Rows[i].FindControl("cbplanFView");
                CheckBox cb4 = (CheckBox)gvauthview.Rows[i].FindControl("cbplanView");
                CheckBox cb5 = (CheckBox)gvauthview.Rows[i].FindControl("cbWorkFlowView");
                CheckBox cb6 = (CheckBox)gvauthview.Rows[i].FindControl("cbSheetEdit");
                CheckBox cb7 = (CheckBox)gvauthview.Rows[i].FindControl("cbSheetView");
                CheckBox cb8 = (CheckBox)gvauthview.Rows[i].FindControl("cbUpdocument");
                CheckBox cb9 = (CheckBox)gvauthview.Rows[i].FindControl("cbIndex_document");
                cb3.Checked = this.cbALL2.Checked;
                cb4.Checked = this.cbALL2.Checked;
                cb5.Checked = this.cbALL2.Checked;
                cb6.Checked = this.cbALL2.Checked;
                cb7.Checked = this.cbALL2.Checked;
                cb8.Checked = this.cbALL2.Checked;
                cb9.Checked = this.cbALL2.Checked;
            }
        }

        protected void cbALL3_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < gvauthview.Rows.Count; i++)
            {
                CheckBox cb10 = (CheckBox)gvauthview.Rows[i].FindControl("cbCustomerView");
                CheckBox cb11 = (CheckBox)gvauthview.Rows[i].FindControl("cbcustomerEdit");
                CheckBox cb42 = (CheckBox)gvauthview.Rows[i].FindControl("CheckBox1");
                cb10.Checked = this.cbALL3.Checked;
                cb11.Checked = this.cbALL3.Checked;
                cb42.Checked = this.cbALL3.Checked;
            }
        }

        protected void cbALL4_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < gvauthview.Rows.Count; i++)
            {
                CheckBox cb12 = (CheckBox)gvauthview.Rows[i].FindControl("cbBillView");
                CheckBox cb13 = (CheckBox)gvauthview.Rows[i].FindControl("cbMonthCustomView");
                CheckBox cb14 = (CheckBox)gvauthview.Rows[i].FindControl("cbAudit");
                CheckBox cb15 = (CheckBox)gvauthview.Rows[i].FindControl("cbReject");
                CheckBox cb16 = (CheckBox)gvauthview.Rows[i].FindControl("cbReceivables");
                CheckBox cb17 = (CheckBox)gvauthview.Rows[i].FindControl("cbActualReceivables");
                cb12.Checked = this.cbALL4.Checked;
                cb13.Checked = this.cbALL4.Checked;
                cb14.Checked = this.cbALL4.Checked;
                cb15.Checked = this.cbALL4.Checked;
                cb16.Checked = this.cbALL4.Checked;
                cb17.Checked = this.cbALL4.Checked;
               
            }
        }

        protected void cbALL5_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < gvauthview.Rows.Count; i++)
            {
                CheckBox cb18 = (CheckBox)gvauthview.Rows[i].FindControl("cbExcel_docment");
                CheckBox cb19 = (CheckBox)gvauthview.Rows[i].FindControl("cbYSshou");
                CheckBox cb20 = (CheckBox)gvauthview.Rows[i].FindControl("cbyuangongyewutongji");
                CheckBox cb21 = (CheckBox)gvauthview.Rows[i].FindControl("cbyewushujutongji");
                cb18.Checked = this.cbALL5.Checked;
                cb19.Checked = this.cbALL5.Checked;
                cb20.Checked = this.cbALL5.Checked;
                cb21.Checked = this.cbALL5.Checked;
            }
        }

        protected void cbALL6_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < gvauthview.Rows.Count; i++)
            {
                CheckBox cb22 = (CheckBox)gvauthview.Rows[i].FindControl("cbScoreView");
                CheckBox cb23 = (CheckBox)gvauthview.Rows[i].FindControl("cbMessage");
                cb22.Checked = this.cbALL6.Checked;
                cb23.Checked = this.cbALL6.Checked;
            }
        }

        protected void cbALL7_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < gvauthview.Rows.Count; i++)
            {
                CheckBox cb24 = (CheckBox)gvauthview.Rows[i].FindControl("cbKnowledgeView0");
                CheckBox cb25 = (CheckBox)gvauthview.Rows[i].FindControl("cbKnowledgeView1");
                CheckBox cb26 = (CheckBox)gvauthview.Rows[i].FindControl("cbKnowledgeView2");
                CheckBox cb27 = (CheckBox)gvauthview.Rows[i].FindControl("cbKnowledgeView3");
                CheckBox cb28 = (CheckBox)gvauthview.Rows[i].FindControl("cbknowledgeView5");
                CheckBox cb29 = (CheckBox)gvauthview.Rows[i].FindControl("cbKnowledgeUpload");
                cb24.Checked = this.cbALL7.Checked;
                cb25.Checked = this.cbALL7.Checked;
                cb26.Checked = this.cbALL7.Checked;
                cb27.Checked = this.cbALL7.Checked;
                cb28.Checked = this.cbALL7.Checked;
                cb29.Checked = this.cbALL7.Checked;

            }
        }

        protected void cbALL8_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < gvauthview.Rows.Count; i++)
            {
                CheckBox cb30 = (CheckBox)gvauthview.Rows[i].FindControl("cbindex_fee");
                CheckBox cb31 = (CheckBox)gvauthview.Rows[i].FindControl("cbfeeTemplateView");
                CheckBox cb32 = (CheckBox)gvauthview.Rows[i].FindControl("cbmodelset");
                CheckBox cb33 = (CheckBox)gvauthview.Rows[i].FindControl("cbEXCELSetting");
                CheckBox cb34 = (CheckBox)gvauthview.Rows[i].FindControl("cbAddCode");
                CheckBox cb35 = (CheckBox)gvauthview.Rows[i].FindControl("cbIndex_job");
                CheckBox cb36 = (CheckBox)gvauthview.Rows[i].FindControl("cbCodeIndex");
                CheckBox cb37 = (CheckBox)gvauthview.Rows[i].FindControl("cbEmpIndex");
                CheckBox cb38 = (CheckBox)gvauthview.Rows[i].FindControl("cbAddEmp");
                CheckBox cb39 = (CheckBox)gvauthview.Rows[i].FindControl("cbUserPasswordChange");
                cb30.Checked = this.cbALL8.Checked;
                cb31.Checked = this.cbALL8.Checked;
                cb32.Checked = this.cbALL8.Checked;
                cb33.Checked = this.cbALL8.Checked;
                cb34.Checked = this.cbALL8.Checked;
                cb35.Checked = this.cbALL8.Checked;
                cb36.Checked = this.cbALL8.Checked;
                cb37.Checked = this.cbALL8.Checked;
                cb38.Checked = this.cbALL8.Checked;
                cb39.Checked = this.cbALL8.Checked;
               
            }
        }

        protected void cbALL9_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < gvauthview.Rows.Count; i++)
            {
                CheckBox cb40 = (CheckBox)gvauthview.Rows[i].FindControl("cbAuthManage");
                CheckBox cb41 = (CheckBox)gvauthview.Rows[i].FindControl("cbDatabase");
                cb40.Checked = this.cbALL9.Checked;
                cb41.Checked = this.cbALL9.Checked;
            }
        }

        #endregion
    }
}
